package com.company.test29;

import java.util.concurrent.Semaphore;

/**
 * Created by v on 16-11-28.
 */
public class Test2912 {
    private static Semaphore semaphore=new Semaphore(1);
    private int balance=0;

    public int getBalance(){
        return balance;
    }

    public void deposit(int amount){
        try {
            semaphore.acquire();
            int newBalance=balance+amount;

            Thread.sleep(5);

            balance=newBalance;
        }catch (InterruptedException ex){
            ex.printStackTrace();
        }finally {
            semaphore.release();
        }
    }
}
